package com.yy.jhl.ui.user.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.yy.common.base.BaseActivity;
import com.yy.common.baseapp.AppManager;
import com.yy.common.commonutils.StringUtil;
import com.yy.common.commonwidget.OnDoubleClickListener;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.app.MyApplication;
import com.yy.jhl.ui.user.contract.ModifyPwdContract;
import com.yy.jhl.ui.user.presenter.ModifyPwdPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by libingn on 2017/12/4.
 */

public class ModifyPwdActivity extends BaseActivity<ModifyPwdPresenter> implements ModifyPwdContract.View {

    @BindView(R.id.old_pwd_edit)
    EditText oldPwdEdit;
    @BindView(R.id.new_pwd_edit)
    EditText newPwdEdit;
    @BindView(R.id.new_ensure_pwd_edit)
    EditText newEnsurePwdEdit;
    @BindView(R.id.ensure_btn)
    Button ensureBtn;

    @Override
    public int getLayoutId() {
        return R.layout.act_modify_pwd;
    }

    @Override
    public void initView() {
        showTitle("密码修改", new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
    }

    @OnClick(R.id.ensure_btn)
    public void onViewClicked() {
        String old_pwd = oldPwdEdit.getText().toString().trim();
        String pwd = newPwdEdit.getText().toString().trim();
        String new_pwd = newEnsurePwdEdit.getText().toString().trim();
        if (StringUtil.isEmpty(old_pwd)){
            showShortToast("旧密码不能为空");
            return;
        }
        if (old_pwd.length() < 6 || old_pwd.length() > 30){
            showShortToast("请输入6-30位的旧密码");
            return;
        }
        if (StringUtil.isEmpty(pwd)){
            showShortToast("新密码不能为空");
            return;
        }
        if (pwd.length() < 6 || pwd.length() > 30){
            showShortToast("请输入6-30位的新密码");
            return;
        }
        if (StringUtil.isEmpty(new_pwd)){
            showShortToast("确认密码不能为空");
            return;
        }
        if (new_pwd.length() < 6 || new_pwd.length() > 30){
            showShortToast("请输入6-30位的确认密码");
            return;
        }
        if (!pwd.equals(new_pwd)){
            showShortToast("密码输入不一致");
            return;
        }
        mPresenter.modifyPwd(old_pwd,pwd,new_pwd);
    }

    @Override
    public void modifySuccess() {
        showShortToast("修改密码成功");
        MyApplication.getInstance().clearData();
        AppManager.getAppManager().finishAllActivity();
        startActivity(LoginSelectActivity.class);
    }

    @Override
    public void modifyFail() {

    }
}
